<template>
  <zm-dialog
    :title="PTitle"
    :visible.sync="value"
    append-to-body
    size="small"
    :before-close="dialogClose"
    :close-on-click-modal="false"
  >
    <zm-form :model="form" ref="form" :rules="Rules" label-width="100px">
      <el-form-item label="客户名称：" prop="customerId">
        <zm-data-select
          v-model="form.customerId"
          api="getMyCustomerList"
          :params="{}"
          placeholder="客户名称"
          value-key="id"
          label-name="customerName"
          class="w300"
        ></zm-data-select>
      </el-form-item>
      <el-form-item label="跟进方式：" prop="followType">
        <zm-data-select
          v-model="form.followType"
          k1="followType"
          placeholder="跟进方式"
          class="w300"
        ></zm-data-select>
      </el-form-item>

      <el-form-item label="跟进目的：" prop="followPurpose">
        <zm-data-select
          v-model="form.followPurpose"
          k1="followPurpose"
          placeholder="跟进目的"
          class="w300"
        ></zm-data-select>
      </el-form-item>
      <el-form-item label="跟进时间：" prop="followTime">
        <zm-date-picker type="date" v-model="form.followTime" />
      </el-form-item>
      <el-form-item label="跟进内容：" prop="content">
        <zm-input
          type="textarea"
          v-model="form.content"
          placeholder="勤跟进，多签单，多绩效提成"
          :autosize="{ minRows: 3 }"
          :maxlength="500"
          class="w400"
        />
      </el-form-item>
      <el-form-item label="查阅人员：" prop="consultAccountId">
        <zm-data-select
          v-model="form.consultAccountId"
          api="getConsultAccountList"
          placeholder="查阅人员"
          value-key="id"
          label-name="realName"
          class="w300"
        ></zm-data-select>
      </el-form-item>
    </zm-form>
    <div slot="footer" class="tr">
      <el-button size="small" @click="dialogClose">取消</el-button>
      <el-button type="primary" size="small" @click="submit">确定</el-button>
    </div>
  </zm-dialog>
</template>
<script>
import dialogMixin from '@/mixins/dialogMixin'
import {detail,
  update,
  create} from '@/api/src/follow'
import { dft } from '@/utils'

export default {
  name: 'NewFollow',
  components: {},
  mixins: [dialogMixin],
  prop: {},
  data () {
    return {
      form: {
        customerId: '',
        followType: '1',
        followPurpose: '1',
        followTime: dft('now', 'YYYY-MM-DD'),
        content: '',
        consultAccountId: ''
      },
      Rules: {
        customerId: {
          required: true,
          message: '请输入客户名称',
          trigger: 'change'
        },
        followType: {
          required: true,
          message: '请选择跟进类型',
          trigger: 'change'
        },
        followPurpose: {
          required: true,
          message: '请选择跟进目的',
          trigger: 'change'
        },
        followTime: {
          required: true,
          message: '请选择跟进时间',
          trigger: 'change'
        },
        content: {
          required: true,
          message: '请选择内容',
          trigger: 'change'
        },
        consultAccountId: {
          required: true,
          message: '请选择查阅人',
          trigger: 'change'
        }
      }
    }
  },
  computed: {
    PTitle () {
      return this.obj.id ? '编辑跟进' : '创建跟进'
    }
  },
  created () {
    if (this.obj.id) this.getInfo()
  },
  methods: {
    async getInfo () {
      const form = await detail({ id: this.obj.id })
      Object.assign(this.form, form)
    },
    async submit () {
      let _valid = false
      this.$refs.form.validate(valid => {
        _valid = valid
      })
      if (!_valid) return

      const _api = this.obj.id ? update : create
      await _api(this.form)
      this.$message.success(this.obj.id ? '编辑成功' : '创建成功')
      this.$emit('after')
      this.dialogClose()
    }
  }
}
</script>
<style lang="scss" scoped></style>
